﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using EnterpriseServices.DalEf;

namespace ServiceTest
{
    class Program
    {
        static void Main(string[] args)
        {


            #region boring testing stuff directly against the database

            using (ESDBEntities _esdb = new ESDBEntities())
            {

                List<Role> _roles = _esdb.Roles_SelectRolesByUser("FMS", @"WGINT\nichsr27").ToList();
                _roles.ForEach(r => Console.WriteLine(r.RoleName));

                _roles = _esdb.Roles_SelectRolesByUser("FMS", @"WGINT\nichsr27").ToList();
                _roles.ForEach(r => Console.WriteLine(r.RoleName));

                Console.WriteLine("User in Application:");
                List<User> _user = _esdb.User_GetUsersByApplicationName("FMS").ToList();
                _user.ForEach(u => Console.WriteLine(u.UserName));

                //var _groups = _esdb.Groups.ToList();

                //var _groups = (from g in _esdb.Groups
                //               select g).ToList();

                //_groups.ForEach(g => Console.WriteLine("Associated groups to " + g.GroupName + " are:"));

                //_esdb.GroupAssociations_SelectAssociatedGroups("FMS").ToList().ForEach(ga =>
                //    (from g in _esdb.Groups
                //     where g.GroupId == ga.AssociatedGroupId
                //     select g)
                //    .ToList()
                //    .ForEach(g => Console.WriteLine(g.GroupName)));

                //Console.WriteLine(_esdb.ExtendedProcs.Users_DoesUserExists(@"WGINT\nichsr27").ToString());

                //_esdb.Roles_SelectRolesByUser("FMS", @"WGINT\nichsr27").ToList().ForEach(r =>
                //    Console.WriteLine(r.RoleName));

            }

            #endregion

            
            #region testing stuff against the service
            
            DateTime _start = DateTime.Now;

            //for (int i = 0; i < 50; i++)
            //{
            //    Console.WriteLine(i.ToString() + " : " + EnterpriseServices.Service.ValidationManagerRemotingProxy.sharedInstance().DoesUserExist("Sebastian").ToString());
            //}

            Console.WriteLine("Does user exist: " + EnterpriseServices.Service.ValidationManagerRemotingProxy.sharedInstance().DoesUserExist(@"WGINT\nichsr27"));

            Console.WriteLine("Is Sebastian in FMS SecurityAdministrator role: " + EnterpriseServices.Service.ValidationManagerRemotingProxy.sharedInstance().IsUserInRole("FMS", "SecurityAdministrator", @"WGINT\nichsr27"));

            Console.WriteLine("");

            Console.WriteLine("Scott belongs to these FMS roles:");
            EnterpriseServices.Service.RoleManagerRemotingProxy.sharedInstance().GetRolesByUser("FMS", @"WGINT\nichsr27")
                .ForEach(r => Console.WriteLine(r.RoleName));

            Console.WriteLine((DateTime.Now - _start).Ticks.ToString());
            Console.WriteLine("Ended testing of ValidationManagerRemoting.");

            #endregion


            Console.ReadKey();

        }
    }
}
